package ericXie.com.bussiness 
{
	import ericXie.com.interfaces.IDataResponder;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	
	/**
	 * ...加载SWF元素
	 * @author EricXie
	 */
	public class LoadElementDelegate implements IDataResponder 
	{
		private var servers:Loader;
		private var context:LoaderContext
		private var _responder:IDataResponder;
		private var request:URLRequest;
		public function LoadElementDelegate(responder:IDataResponder) 
		{
			_responder = responder;
			this.servers = new Loader();
			request = new URLRequest();
			context=new LoaderContext()
			/* 加载到同域(共享库) */
			context.applicationDomain = ApplicationDomain.currentDomain;
		}
		public function readConfig(path:String):void
		{
			request.url = path;	
			servers.contentLoaderInfo.addEventListener(Event.COMPLETE, result)
			servers.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, fault)
			servers.load(new URLRequest(path), context);
		}
		public function result(evt:Event):void
		{
			_responder.result(evt);
		}
		
		public function fault(evt:IOErrorEvent):void
		{
			
			_responder.fault(evt);
		}
		public function progress(evt:ProgressEvent):void {
			_responder.progress(evt);
		}
		
	}

}